package weaver.jobs.zjj.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.docs.webservices.DocAttachment;
import weaver.docs.webservices.DocInfo;
import weaver.docs.webservices.DocServiceImpl;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.*;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-06-17
 * @Description: ${description}
 * @ModifyLog:
 **/

public class ZjjUtil {
    public static void main(String[] args) throws Exception{
        JSONObject caseInfo = new JSONObject();
        caseInfo.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
        String CaseGuid = "20220812151142749_882f73d53d77467fb09fdeed257a1bfe";
        caseInfo.put( "CaseGuid", Util.null2String( CaseGuid ) );
        JSONObject caseInfoResult = SelectCaseInfo_OU( caseInfo );
        System.out.println(caseInfoResult);
        JSONObject attach = new JSONObject();
        attach.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
        String AttachGuid ="5b4a832b-51aa-4817-a271-5c04a272c4da";
        attach.put( "AttachGuid", AttachGuid );
        JSONObject attachResult = ZjjUtil.SelectAttach( attach );
        String AttContent = attachResult.getString( "AttContent" );
        String AttFileName = attachResult.getString( "AttFileName" );
        System.out.println("AttContent="+AttContent+",AttFileName="+AttFileName);

    }

    public static void test() throws Exception {
        JSONObject json = new JSONObject();
        json.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
        json.put( "LoginID", "36ecf76e-1ef7-45f5-98e6-e71e2b2f1402" );
        json.put( "password", "123456" );
        JSONObject userLoginResult = UserLogin( json );
        String LoginStatus = userLoginResult.getString( "Status" );
        if ("1".equals( LoginStatus )) {
            String UserGuid = userLoginResult.getString( "UserGuid" );
            JSONObject waitHandleList = new JSONObject();
            waitHandleList.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
            waitHandleList.put( "UserGuid", UserGuid );
            waitHandleList.put( "Title", "" );
            waitHandleList.put( "SearchFromDate", "2023-02-27" );
            waitHandleList.put( "SearchToDate", "2022-09-07" );
            waitHandleList.put( "PageSize", "100" );
            waitHandleList.put( "CurrentPageIndex", "1" );
            JSONObject waitHandleListResult = SelectWaitHandleList( waitHandleList );
            String waitStatus = waitHandleListResult.getString( "Status" );
            if ("1".equals( waitStatus )) {
                String WaithandleList = waitHandleListResult.getString( "WaithandleList" );
                JSONObject PageInfo = waitHandleListResult.getJSONObject( "PageInfo" );
                String TotalNumCount = PageInfo.getString( "TotalNumCount" );
                String TotalPageCount = PageInfo.getString( "TotalPageCount" );
                System.out.println( "TotalNumCount=" + TotalNumCount );
                System.out.println( "TotalPageCount=" + TotalPageCount );
                JSONArray WaithandleArray = JSONArray.parseArray( WaithandleList );
                System.out.println( "WaithandleArray="+WaithandleArray.size() );
                for (int i = 0; i < WaithandleArray.size(); i++) {

                    String CaseGuid = WaithandleArray.getJSONObject( i ).getString( "CaseGuid" );
                    String TaskGuid = WaithandleArray.getJSONObject( i ).getString( "TaskGuid" );
                    String Title = WaithandleArray.getJSONObject( i ).getString( "Title" );

                    JSONObject caseInfo = new JSONObject();
                    caseInfo.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
                    caseInfo.put( "CaseGuid", Util.null2String( CaseGuid ) );
                    JSONObject caseInfoResult = SelectCaseInfo_OU( caseInfo );
                    System.out.println( "caseInfoResult=" + caseInfoResult.toJSONString() );

//                    JSONObject taskInfo = new JSONObject();
//                    taskInfo.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
//                    taskInfo.put( "TaskGuid", Util.null2String( TaskGuid ) );
//                    JSONObject taskInfoResult = SelectTaskInfo_OU( taskInfo );
//                    System.out.println( "taskInfoResult=" + taskInfoResult.toJSONString() );
//                    JSONObject signIn = new JSONObject();
//                    signIn.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
//                    signIn.put( "UserGuid", UserGuid );
//                    signIn.put( "TaskGuid", Util.null2String( TaskGuid ) );
//                    signIn.put( "SignInDate", DateUtil.getCurrentDate() );
                    //JSONObject signInResult = WaitHandleSignIn(signIn);
                    //System.out.println( "signInResult=" + signInResult.toJSONString() );
                   /* String CaseAttachList = Util.null2String( caseInfoResult.getString( "CaseAttachList" ) );
                    JSONArray resuletArray = JSONArray.parseArray( CaseAttachList );
                    if (resuletArray.size() > 0) {
                        for (int j = 0; j < resuletArray.size(); j++) {
                            String CaseAttachGuid = resuletArray.getJSONObject( j ).getString( "CaseAttachGuid" );
                            String CaseAttachName = resuletArray.getJSONObject( j ).getString( "CaseAttachName" );
                            JSONObject attach = new JSONObject();
                            attach.put( "IdentityGuid", "Epoint_WebSerivce_**##0601" );
                            attach.put( "AttachGuid", CaseAttachGuid );
                            JSONObject attachResult = SelectAttach( attach );
                            String AttContent = attachResult.getString( "AttContent" );
                            String AttFileName = attachResult.getString( "AttFileName" );
                            createDoc( new User( 1 ), AttFileName, AttContent, 90 );

                        }
                    }*/
                }
            }
        }
    }

    /*
     * @Description: 用于部门用户登录接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject UserLogin(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        String method = "UserLogin";
        String param = "xmlUserInfo";
        String soapAction = "SOAPAction";
        String message = InvokeHandle( paramJson, method,soapAction, param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            if ("1".equals( Status )) {
                Element UserArea = DATA.element( "UserArea" );
                String UserGuid = UserArea.element( "UserGuid" ).getTextTrim();
                String DisplayName = UserArea.element( "DisplayName" ).getTextTrim();
                String OUGuid = UserArea.element( "OUGuid" ).getTextTrim();
                returnJson.put( "UserGuid", Util.null2String( UserGuid ) );
                returnJson.put( "DisplayName", Util.null2String( DisplayName ) );
                returnJson.put( "OUGuid", Util.null2String( OUGuid ) );
            } else {
                String Description = ReturnInfo.element( "Description" ).getTextTrim();
                returnJson.put( "Description", Util.null2String( Description ) );
            }
        }
        return returnJson;
    }


    /*
     * @Description: 获得待办事宜列表接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject SelectWaitHandleList(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String method = "SelectWaitHandleList";
        String param = "xmlUserGuid";
        String soapAction = "SOAPAction";
        String message = InvokeHandle( paramJson, method,soapAction, param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            if ("1".equals( Status )) {
                JSONObject pageInfoJson = new JSONObject();
                Element PageInfo = DATA.element( "PageInfo" );
                String TotalNumCount = PageInfo.element( "TotalNumCount" ).getTextTrim();
                String TotalPageCount = PageInfo.element( "TotalPageCount" ).getTextTrim();
                pageInfoJson.put( "TotalNumCount", Util.null2String( TotalNumCount ) );
                pageInfoJson.put( "TotalPageCount", Util.null2String( TotalPageCount ) );
                returnJson.put( "PageInfo", pageInfoJson );
                Element UserArea = DATA.element( "UserArea" );
                Element WaithandleList = UserArea.element( "WaithandleList" );
                List<Element> listElement = WaithandleList.elements();
                for (Element e : listElement) {//遍历所有一级子节点
                    JSONObject json = new JSONObject();
                    String Title = e.element( "Title" ).getTextTrim();
                    String CreateDate = e.element( "CreateDate" ).getTextTrim();
                    String OverTimePoint = e.element( "OverTimePoint" ).getTextTrim();
                    String TimeLeft = e.element( "TimeLeft" ).getTextTrim();
                    String MessageItemGuid = e.element( "MessageItemGuid" ).getTextTrim();
                    String CaseGuid = e.element( "CaseGuid" ).getTextTrim();
                    String TaskGuid = e.element( "TaskGuid" ).getTextTrim();
                    json.put( "Title", Util.null2String( Title ) );
                    json.put( "CreateDate", Util.null2String( CreateDate ) );
                    json.put( "OverTimePoint", Util.null2String( OverTimePoint ) );
                    json.put( "TimeLeft", Util.null2String( TimeLeft ) );
                    json.put( "MessageItemGuid", Util.null2String( MessageItemGuid ) );
                    json.put( "CaseGuid", Util.null2String( CaseGuid ) );
                    json.put( "TaskGuid", Util.null2String( TaskGuid ) );
                    jsonArray.add( json );
                }
                returnJson.put( "WaithandleList", jsonArray );
            } else {
                String Description = ReturnInfo.element( "Description" ).getTextTrim();
                returnJson.put( "Description", Util.null2String( Description ) );
            }

        }
        return returnJson;
    }

    /*
     * @Description: 待办事宜签收接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject WaitHandleSignIn(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        String method = "WaitHandleSignIn";
        String param = "xmlTaskGuid";
        String soapAction = "action";
        String message = InvokeHandle( paramJson, method, soapAction,param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            String Description = ReturnInfo.element( "Description" ).getTextTrim();
            returnJson.put( "Description", Util.null2String( Description ) );
        }
        return returnJson;
    }


    /*
     * @Description: 用于数据工单信息显示接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject SelectCaseInfo(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        String method = "SelectCaseInfo";
        String param = "xmlCaseInfo";
        String soapAction = "SOAPAction";
        String message = InvokeHandle( paramJson, method,soapAction, param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            if ("1".equals( Status )) {
                Element UserArea = DATA.element( "UserArea" );
                String CaseGuid = UserArea.element( "CaseGuid" ).getTextTrim();
                String CaseSerial = UserArea.element( "CaseSerial" ).getTextTrim();
                String RequestDate = UserArea.element( "RequestDate" ).getTextTrim();
                String RequestNumber = UserArea.element( "RequestNumber" ).getTextTrim();
                String RequestPerson = UserArea.element( "RequestPerson" ).getTextTrim();
                String RequestPersonGuid = UserArea.element( "RequestPersonGuid" ).getTextTrim();
                String RequestTitle = UserArea.element( "RequestTitle" ).getTextTrim();
                String Description = UserArea.element( "Description" ).getTextTrim();
                String RequestNote = UserArea.element( "RequestNote" ).getTextTrim();
                String CaseType = UserArea.element( "CaseType" ).getTextTrim();
                String AuditDate = UserArea.element( "AuditDate" ).getTextTrim();
                String AuditOpinion = UserArea.element( "AuditOpinion" ).getTextTrim();
                String LingDaoPiShi = UserArea.element( "LingDaoPiShi" ).getTextTrim();
                String AnswerDate = UserArea.element( "AnswerDate" ).getTextTrim();
                String AnswerContent = UserArea.element( "AnswerContent" ).getTextTrim();
                returnJson.put( "CaseGuid", Util.null2String( CaseGuid ) );
                returnJson.put( "CaseSerial", Util.null2String( CaseSerial ) );
                returnJson.put( "RequestDate", Util.null2String( RequestDate ) );
                returnJson.put( "RequestNumber", Util.null2String( RequestNumber ) );
                returnJson.put( "RequestPerson", Util.null2String( RequestPerson ) );
                returnJson.put( "RequestPersonGuid", Util.null2String( RequestPersonGuid ) );
                returnJson.put( "RequestTitle", Util.null2String( RequestTitle ) );
                returnJson.put( "Description", Util.null2String( Description ) );
                returnJson.put( "RequestNote", Util.null2String( RequestNote ) );
                returnJson.put( "CaseType", Util.null2String( CaseType ) );
                returnJson.put( "AuditDate", Util.null2String( AuditDate ) );
                returnJson.put( "AuditOpinion", Util.null2String( AuditOpinion ) );
                returnJson.put( "LingDaoPiShi", Util.null2String( LingDaoPiShi ) );
                returnJson.put( "AnswerDate", Util.null2String( AnswerDate ) );
                returnJson.put( "AnswerContent", Util.null2String( AnswerContent ) );
                Element CaseAttachList = UserArea.element( "CaseAttachList" );
                List<Element> listElement = CaseAttachList.elements();
                JSONArray jsonArray = new JSONArray();
                for (Element e : listElement) {//遍历所有一级子节点
                    JSONObject json = new JSONObject();
                    String CaseAttachGuid = e.element( "CaseAttachGuid" ).getTextTrim();
                    String CaseAttachName = e.element( "CaseAttachName" ).getTextTrim();
                    json.put( "CaseAttachGuid", Util.null2String( CaseAttachGuid ) );
                    json.put( "CaseAttachName", Util.null2String( CaseAttachName ) );
                    jsonArray.add( json );
                }
                returnJson.put( "CaseAttachList", jsonArray );
            } else {
                String Description = ReturnInfo.element( "Description" ).getTextTrim();
                returnJson.put( "Description", Util.null2String( Description ) );
            }
        }
        return returnJson;
    }

    /*
     * @Description: 用于部门展示工单信息
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject SelectCaseInfo_OU(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        String method = "SelectCaseInfo_OU";
        String param = "xmlCaseInfo";
        String soapAction = "SOAPAction";
        String message = InvokeHandle( paramJson, method,soapAction, param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            if ("1".equals( Status )) {
                Element UserArea = DATA.element( "UserArea" );
                String CaseGuid = UserArea.element( "CaseGuid" ).getTextTrim();
                String CaseSerial = UserArea.element( "CaseSerial" ).getTextTrim();
                String RequestDate = UserArea.element( "RequestDate" ).getTextTrim();
                String RequestNumber = UserArea.element( "RequestNumber" ).getTextTrim();
                String RequestPerson = UserArea.element( "RequestPerson" ).getTextTrim();
                String RequestPersonGuid = UserArea.element( "RequestPersonGuid" ).getTextTrim();
                String RequestTitle = UserArea.element( "RequestTitle" ).getTextTrim();
                String Description = UserArea.element( "Description" ).getTextTrim();
                String RequestNote = UserArea.element( "RequestNote" ).getTextTrim();
                String CaseType = UserArea.element( "CaseType" ).getTextTrim();
                String Address = UserArea.element( "Address" ).getTextTrim();
                String Xy = UserArea.element( "Xy" ).getTextTrim();
                String Tel = UserArea.element( "Tel" ).getTextTrim();
                returnJson.put( "CaseGuid", Util.null2String( CaseGuid ) );
                returnJson.put( "CaseSerial", Util.null2String( CaseSerial ) );
                returnJson.put( "RequestDate", Util.null2String( RequestDate ) );
                returnJson.put( "RequestNumber", Util.null2String( RequestNumber ) );
                returnJson.put( "RequestPerson", Util.null2String( RequestPerson ) );
                returnJson.put( "RequestPersonGuid", Util.null2String( RequestPersonGuid ) );
                returnJson.put( "RequestTitle", Util.null2String( RequestTitle ) );
                returnJson.put( "Description", Util.null2String( Description ) );
                returnJson.put( "RequestNote", Util.null2String( RequestNote ) );
                returnJson.put( "CaseType", Util.null2String( CaseType ) );
                returnJson.put( "Address", Util.null2String( Address ) );
                returnJson.put( "Xy", Util.null2String( Xy ) );
                returnJson.put( "Tel", Util.null2String( Tel ) );
                Element AttachGuidList = UserArea.element( "AttachGuidList" );
                List<Element> listElement = AttachGuidList.elements();
                JSONArray jsonArray = new JSONArray();
                //遍历所有一级子节点
                for (Element e : listElement) {
                    JSONObject json = new JSONObject();
                    String AttachGuid = e.element( "AttachGuid" ).getTextTrim();
                    json.put( "AttachGuid", Util.null2String( AttachGuid ) );
                    jsonArray.add( json );
                }
                returnJson.put( "AttachGuidList", jsonArray );
            } else {
                String Description = ReturnInfo.element( "Description" ).getTextTrim();
                returnJson.put( "Description", Util.null2String( Description ) );
            }
        }
        return returnJson;
    }

    /*
     * @Description: 用于部门展示任务单信息接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject SelectTaskInfo_OU(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        String method = "SelectTaskInfo_OU";
        String param = "xmlTaskInfo";
        String soapAction = "SOAPAction";
        String message = InvokeHandle( paramJson, method,soapAction, param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            if ("1".equals( Status )) {
                Element UserArea = DATA.element( "UserArea" );
                String CaseGuid = UserArea.element( "CaseGuid" ).getTextTrim();
                String TaskTitle = UserArea.element( "TaskTitle" ).getTextTrim();
                String CreateDate = UserArea.element( "CreateDate" ).getTextTrim();
                String FeedBackAllowDate = UserArea.element( "FeedBackAllowDate" ).getTextTrim();
                String PromiseDate = UserArea.element( "PromiseDate" ).getTextTrim();
                String TaskContent = UserArea.element( "TaskContent" ).getTextTrim();
                String TaskStatus = UserArea.element( "TaskStatus" ).getTextTrim();

                returnJson.put( "CaseGuid", Util.null2String( CaseGuid ) );
                returnJson.put( "TaskTitle", Util.null2String( TaskTitle ) );
                returnJson.put( "CreateDate", Util.null2String( CreateDate ) );
                returnJson.put( "FeedBackAllowDate", Util.null2String( FeedBackAllowDate ) );
                returnJson.put( "PromiseDate", Util.null2String( PromiseDate ) );
                returnJson.put( "TaskContent", Util.null2String( TaskContent ) );
                returnJson.put( "TaskStatus", Util.null2String( TaskStatus ) );
            } else {
                String Description = ReturnInfo.element( "Description" ).getTextTrim();
                returnJson.put( "Description", Util.null2String( Description ) );
            }
        }
        return returnJson;
    }

    /*
     * @Description: 用于获得附件接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static JSONObject SelectAttach(JSONObject paramJson) throws Exception {
        JSONObject returnJson = new JSONObject();
        String method = "SelectAttach";
        String param = "xmlAttachGuid";
        String soapAction = "SOAPAction";
        String message = InvokeHandle( paramJson, method,soapAction, param );
        Document xmlDocument = DocumentHelper.parseText( message );
        if (xmlDocument != null) {
            Element rootElement = xmlDocument.getRootElement();
            Element DATA = rootElement.element( "DATA" );
            Element ReturnInfo = DATA.element( "ReturnInfo" );
            String Status = ReturnInfo.element( "Status" ).getTextTrim();
            returnJson.put( "Status", Status );
            if ("1".equals( Status )) {
                Element UserArea = DATA.element( "UserArea" );
                Element SingleFile = UserArea.element( "SingleFile" );
                String AttContent = SingleFile.element( "AttContent" ).getTextTrim();
                String AttFileName = SingleFile.element( "AttFileName" ).getTextTrim();
                returnJson.put( "AttContent", Util.null2String( AttContent ) );
                returnJson.put( "AttFileName", Util.null2String( AttFileName ) );
            } else {
                String Description = ReturnInfo.element( "Description" ).getTextTrim();
                returnJson.put( "Description", Util.null2String( Description ) );
            }
        }
        return returnJson;
    }


    /*
     * @Description: 通用调用接口
     * @Param: [paramJson]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/6/20
     */
    public static String InvokeHandle(JSONObject paramJson, String method,String soapAction, String param) {
        String wsdl = "http://2.18.220.226/12345/WebService/_2345Service.asmx";
        String ActionValue = "http://tempuri.org/" + method;
        String Header_beg = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\"><soap:Header/>";
        String Header_end = "</soap:Envelope>";
        String Body_beg = "<soap:Body>";
        String Body_end = "</soap:Body>";
        String Method_beg = "<tem:" + method + ">";
        String Method_end = "</tem:" + method + ">";
        String headXML = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;";
        String xmlUserGuid_beg = "<" + param + ">";
        String xmlUserGuid_end = "</" + param + ">";
        StringBuilder body = new StringBuilder( "&lt;paras&gt;" );
        paramJson.forEach( (key, value) -> {
            body.append( "&lt;" + key + "&gt;" + value + "&lt;/" + key + "&gt;" );
        } );
        body.append( "&lt;/paras&gt;" );
        StringBuilder templateXML = new StringBuilder( Header_beg );
        templateXML.append( Body_beg );
        templateXML.append( Method_beg );
        templateXML.append( xmlUserGuid_beg );
        templateXML.append( headXML );
        templateXML.append( body );
        templateXML.append( xmlUserGuid_end );
        templateXML.append( Method_end );
        templateXML.append( Body_end );
        templateXML.append( Header_end );
        String xml = templateXML.toString();
        String message = doPostSoap( wsdl, xml, soapAction,ActionValue );
        return message;
    }

    /*
     *
     * @param url
     * @param soapXml
     * @param actionName
     * @return
     * @throws Exception
     */
    public static String doPostSoap(String url, String soapXml, String actionName,String actionValue) {
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
        HttpPost httpPost = new HttpPost( url );
        //设置请求和传输超时时间
        String returnResult = "";
        CloseableHttpResponse response = null;
        try {
            httpPost.setHeader( "Content-Type", "text/xml;charset=UTF-8" );
            httpPost.setHeader( actionName, actionValue );
            StringEntity data = new StringEntity( soapXml );
            httpPost.setEntity( data );
            response = closeableHttpClient.execute( httpPost );
            HttpEntity httpEntity = response.getEntity();
            if (httpEntity != null) {
                String result = EntityUtils.toString( httpEntity, "UTF-8" );
                if (!"".equals( result )) {
                    String newresult = result.substring( result.indexOf( "&lt;" ), result.lastIndexOf( "&gt;" ) + 4 );
                    returnResult = StringEscapeUtils.unescapeXml( newresult );
                } else {
                    returnResult = "接口返回结果为空";
                }
            } else {
                returnResult = "sap接口异常";
            }
        } catch (Exception e) {
            System.out.println( "e：" + e );
        }
        return returnResult;
    }

    /*
     *@Description:建模权限重构
     */
    public static void getNewModeRight(int userid, int formmodeid, int id) {
        ModeRightInfo modeRightInfo = new ModeRightInfo();
        modeRightInfo.setNewRight( true );
        modeRightInfo.editModeDataShare( userid, formmodeid, id );
    }

    /*
     *@Description:接口调用日志表
     */
    public static void saveCallInterLog(String jkmc, String fhjg) {
        String rqsj = DateUtil.getFullDate();
        int formmodeid = getFormmodeId( "uf_dbjkrz" );
        Map<String, String> dataMap = new HashMap();
        dataMap.put( "jkmc", jkmc );
        dataMap.put( "jklx", "0" );
        dataMap.put( "qqsj", rqsj );
        dataMap.put( "fhjg", fhjg );
        insertModelData( formmodeid, 1, dataMap );
    }

    /**
     *@Description: 将数据插入表单建模
     */
    public static int insertModelData(int modeid, int userid, Map map) {
        int dataid = 0;
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        //查询该模块表名
        String sql = "select b.tablename,a.formid from modeinfo a left join workflow_bill b on a.formid=b.id where a.id=?";
        rs.executeQuery( sql, modeid );
        rs.next();
        String tablename = Util.null2String( rs.getString( "tablename" ) );
        String uuid = UUID.randomUUID().toString();
        String insSql = "insert into " + tablename
                + "(uuid,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid)values(?,?,?,?,?)";
        Object[] params = {uuid, userid, TimeUtil.getCurrentDateString(), TimeUtil.getOnlyCurrentTimeString(), modeid};
        if (rs.executeUpdate( insSql, params )) {
            rs1.executeQuery( "select id from " + tablename + " where uuid=?", uuid );
            rs1.next();
            dataid = Util.getIntValue( rs1.getString( "id" ) );
            if (dataid > 0) {
                //遍历数据 进行update
                String updatesql = "update " + tablename + " set ";
                Set<String> keySet = map.keySet();
                for (String key : keySet) {
                    updatesql += key + "='" + map.get( key ).toString() + "',";
                }
                if (updatesql.endsWith( "," )) {
                    updatesql = updatesql.substring( 0, updatesql.length() - 1 );
                    updatesql += " where id=" + dataid;
                    rs.executeUpdate( updatesql );
                }
                //进行权限重构
                getNewModeRight( userid, modeid, dataid );
            }
        }
        return dataid;
    }

    /**
     * 更新数据
     *
     * @param modeid 表名
     * @param map    数据集合
     * @param dataid 更新用唯一标识
     * @return
     */
    public static boolean updateModelData(int modeid,int dataid, Map map) {
        RecordSet rs = new RecordSet();
        //查询该模块表名
        String sql1 = "select b.tablename,a.formid from modeinfo a left join workflow_bill b on a.formid=b.id where a.id=?";
        rs.executeQuery( sql1, modeid );
        rs.next();
        String tablename = Util.null2String( rs.getString( "tablename" ) );
        String sql = "update " + tablename + " set  ";
        String valuesStr = "";
        Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Object> entry = it.next();
            String key = Util.null2String( entry.getKey() );
            String value = "'"+Util.null2String( entry.getValue() )+"'";
            if (valuesStr.equals( "" )) {
                valuesStr = key + "=" + value + "";
            } else {
                valuesStr += "," + key + "=" + value + "";
            }
        }
        sql += valuesStr + " where id='" + dataid + "'";
        return rs.execute( sql );
    }


    /*
     *@Description: 获取formmodeid
     */
    public static int getFormmodeId(String tableName) {
        RecordSet rs = new RecordSet();
        rs.executeQuery( "select m.id from modeinfo m left join WORKFLOW_BILL b on m.formid = b.id where b.tablename = ?", tableName );
        rs.next();
        int formmodeid = Util.getIntValue( rs.getString( "id" ) );
        return formmodeid;
    }

    /*
     *@Description: 创建文档
     */
    public static int createDoc(User user, String rawFileName, String content, int secid) {
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog( ">>>>>>createDocs>>>>>>" );
        int docid = -1;
        DocServiceImpl docserviceimpl = new DocServiceImpl();
        DocInfo doc = new DocInfo(); //创建文档
        String keyword = ""; //文档内容
        try {
            DocAttachment[] docattachment = new DocAttachment[1];
            baseBean.writeLog( ">>>>>rawFileName=" + rawFileName );
            String filetype = "";
            if (rawFileName.lastIndexOf( "." ) > -1) {
                filetype = rawFileName.substring( rawFileName.lastIndexOf( "." ) + 1 );
            }

            // 上传附件，创建html文档
            DocAttachment da = new DocAttachment();
            da.setFilename( rawFileName );//附件标题
            da.setFilecontent( content ); //附件内容
            da.setFiletype( filetype ); //imagefiletype
            da.setImagefilename( rawFileName );// 附件标题
            da.setIszip( 1 );//是否压缩
            da.setIsAesEncrype( 0 );//是否加密
            da.setAesCode( "0" );
            da.setIsextfile( "1" ); //附件是否是office类型

            if (filetype.equalsIgnoreCase( "doc" )) {
                da.setDocfiletype( "3" );
            } else if (filetype.equalsIgnoreCase( "xls" )) {
                da.setDocfiletype( "4" );
            } else if (filetype.equalsIgnoreCase( "ppt" )) {
                da.setDocfiletype( "5" );
            } else if (filetype.equalsIgnoreCase( "wps" )) {
                da.setDocfiletype( "6" );
            } else if (filetype.equalsIgnoreCase( "docx" )) {
                da.setDocfiletype( "7" );
            } else if (filetype.equalsIgnoreCase( "xlsx" )) {
                da.setDocfiletype( "8" );
            } else if (filetype.equalsIgnoreCase( "pptx" )) {
                da.setDocfiletype( "9" );
            } else {
                da.setDocfiletype( "2" );
            }
            docattachment[0] = da;
            keyword = rawFileName;
            doc.setAttachments( docattachment );
            doc.setSeccategory( secid );//子目录id
            doc.setDocSubject( keyword );//标题
            doc.setDoccontent( "" );//文档内容
            /*文档属性*/
            doc.setDocType( 1 );
            //文档状态
            doc.setDocStatus( 1 );
            doc.setDocStatusStr( "正常" );
            //新闻类型
            doc.getDocPublishType();
            doc.setPublishable( "文档" );
            doc.setKeyword( keyword );
            docid = docserviceimpl.createDocByUser( doc, user );
            baseBean.writeLog( ">>>>>docid=" + docid );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return docid;
    }

    /*
     *@Description: 工单号唯一编号重复校验
     */
    public static boolean isRepeatCaseGuid(String CaseGuid) {
        RecordSet rs = new RecordSet();
        rs.executeQuery( "select count(id) from uf_dpfdb where gdwybs=?", CaseGuid );
        rs.next();
        int count = Util.getIntValue( rs.getString( 1 ) );
        return count <= 0 ? true : false;
    }
    /*
     *@Description: 根据工单号获取建模数据Id
     */
    public static int getDataIdByCaseGuid(String CaseGuid) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from uf_dpfdb where gdwybs=?",CaseGuid);
        rs.next();
        return Util.getIntValue( rs.getString( "id" ));
    }

    /*
     *@Description: 任务状态 30：待签收，40：正在处理，50：已反馈答案或意见，55：已反馈意见，等待处理结果，60：已反馈处理结果
     */
    public static String getTaskStatusText(String TaskStatus) {
        String TaskStatusText = "";
        switch (TaskStatus){
            case "30":TaskStatusText = "待签收";break;
            case "40":TaskStatusText = "正在处理";break;
            case "50":TaskStatusText = "已反馈答案或意见";break;
            case "55":TaskStatusText = "已反馈意见，等待处理结果";break;
            case "60":TaskStatusText = "已反馈处理结果";break;
            default:TaskStatusText ="未对应状态";
        }
        return TaskStatusText;
    }



}
